#!/bin/bash

# Java Hook 演示脚本

echo "=== Java Hook 学习项目 演示脚本 ==="
echo

# 检查Maven是否安装
if ! command -v mvn &> /dev/null; then
    echo "错误: 未找到Maven，请先安装Maven"
    exit 1
fi

# 编译项目
echo "1. 编译项目..."
mvn clean compile -q
if [ $? -ne 0 ]; then
    echo "编译失败！"
    exit 1
fi
echo "✅ 编译完成"

# 打包项目
echo
echo "2. 打包项目..."
mvn package -q -DskipTests
if [ $? -ne 0 ]; then
    echo "打包失败！"
    exit 1
fi
echo "✅ 打包完成"

# 提供选择菜单
echo
echo "请选择演示方式："
echo "1) 普通运行 (ByteBuddy + Javassist)"
echo "2) Java Agent运行"
echo "3) 运行单元测试"
echo "4) 查看项目结构"
echo

read -p "请输入选择 (1-4): " choice

case $choice in
    1)
        echo
        echo "=== 运行普通演示 ==="
        java -cp target/classes com.example.hook.HookDemo
        ;;
    2)
        echo
        echo "=== 运行Java Agent演示 ==="
        java -javaagent:target/java-hook-learn-1.0-SNAPSHOT.jar \
             -cp target/classes com.example.hook.HookDemo
        ;;
    3)
        echo
        echo "=== 运行单元测试 ==="
        mvn test
        ;;
    4)
        echo
        echo "=== 项目结构 ==="
        tree src/ 2>/dev/null || find src/ -type f | sort
        ;;
    *)
        echo "无效选择！"
        exit 1
        ;;
esac

echo
echo "=== 演示完成 ==="